#pragma once

class AddUserHandler : public JsonRequest<AddUserHandler> 
{
public:
	bool response()
	{
		std::string		name;
		std::string		gid;
		std::string		email;
		std::string		phone;
		std::string		qq;
		sql_string<>	sql;

		request::reset();
		if(false == request::post("name", name)
				|| false == request::post("email", email)
				|| false == request::post("phone", phone)
				|| false == request::post("qq", qq)
				|| false == request::post("gid", gid))
		{
			err << "invalid paramter";
			return false;
		}
		
		sql.format("insert into t_users(gid, name, email, phone, qq)"
				" values(%d, '%q', '%q', '%q', '%q')",
				atoi(gid.c_str()),
				name.c_str(),
				email.c_str(),
				phone.c_str(),
				qq.c_str());
		if(1 != sql::execute(sql.c_str()))
		{
			err << "add user failed:"
				<< sql.c_str();
			return false;
		}
		
		json.push_back(JSONNode("errno", 0));
		return true;
	}
};
